var toEx = (function () {
    /**
     * 导出示例，仅把第一组数据的所有key值，当作表头
     * 且数据结构也与第一组保持一致
     * 实际情况根据自身逻辑重写代码
     * @param {} data 
     */
    function exportToExcel(data) {
        //获取第一组数据的keys
        var title = Object.keys(data[0]);
        //组织数据，添加表头
        var table = [title.join(',')];
        data.forEach(d => {
            var line = []
            //整理每一组数据
            title.forEach(t => {
                line.push(d[t]);
            });
            table.push(line.join(','))
        });
        //创建a链接
        var a = document.createElement("a");
        //生成文件数据
        a.href = 'data:application/vnd.ms-excel;charset=utf-8,\ufeff' + encodeURIComponent(table.join('\r\n'))
        //设置导出文件的文件名
        a.download = "导出的文件名";//自定义修改
        document.body.appendChild(a);
        //出发a链接点击事件
        a.click();
        //删除a链接
        document.body.removeChild(a);
    }
    return {
        exportToExcel
    }
})()

var dataType = {
    txt: "data:text/plain;base64",
    doc: "data:application/msword;base64",
    docx: "data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64",
    xls: "data:application/vnd.ms-excel;base64",
    xlsx: "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64",
    pdf: "data:application/pdf;base64",
    pptx: "data:application/vnd.openxmlformats-officedocument.presentationml.presentation;base64",
    ppt: "data:application/vnd.ms-powerpoint;base64",
    png: "data:image/png;base64",
    jpg: "data:image/jpeg;base64",
    gif: "data:image/gif;base64",
    svg: "data:image/svg+xml;base64",
    ico: "data:image/x-icon;base64",
    bmp: "data:image/bmp;base64",
}